﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CMS_Admin_block_NoticeListSet : System.Web.UI.Page
{
    Usas.BLL.Cms.cms_block cb = new Usas.BLL.Cms.cms_block();
    Usas.BLL.Cms.cms_block_common_detail cbcd = new Usas.BLL.Cms.cms_block_common_detail();
    Usas.BLL.Cms.cms_block_common_detail_option cop = new Usas.BLL.Cms.cms_block_common_detail_option();

    Usas.Model.Cms.cms_block_common_detail cbcdm = new Usas.Model.Cms.cms_block_common_detail();
    Usas.Model.Cms.cms_block_common_detail_option copm = new Usas.Model.Cms.cms_block_common_detail_option();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string action = Request["action"].ToString();

            switch (action)
            {
                case "add":
                    save.Visible = false;
                    rbStatus.Enabled = false;
                    rbStatus.SelectedValue = "2";
                   
                    break;
                case "edit":
                    add.Visible = false;
                    Bind();
                    break;
            }
        }
    }

    private void Bind()
    {
        cbcdm = cbcd.GetModel(Convert.ToInt32(Request["cid"]));
        txtName.Text = cbcdm.c_des;
        rbStatus.SelectedValue = cbcdm.c_view.ToString();
        Fck.Value = cbcdm.c_value;
    }

    protected void add_Click(object sender, EventArgs e)
    {
        cbcdm.c_view = Convert.ToInt32(rbStatus.SelectedValue);
        cbcdm.c_des = txtName.Text.Trim();
        cbcdm.c_type = Request["page"].ToString();
        cbcdm.c_b_id = Convert.ToInt32(Request["control"]);
        cbcdm.c_value = Fck.Value;
        int Nid = cbcd.Add(cbcdm);
        if (Nid > 1)
        {
            ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('添加成功');location.href='" + "NoticeListSet.aspx?action=edit&page="
                + Request["page"].ToString() + "&control=" + Request["control"].ToString() + "&cid=" + Nid + "'", true);
        }
    }

    protected void save_Click(object sender, EventArgs e)
    {
        cbcdm.c_view = Convert.ToInt32(rbStatus.SelectedValue);
        cbcdm.c_value = Fck.Value;
        cbcdm.c_type = Request["page"].ToString();
        cbcdm.c_b_id = Convert.ToInt32(Request["control"]);
        cbcdm.c_id = Convert.ToInt32(Request["cid"]);
        cbcdm.c_des = txtName.Text.Trim();
        cbcd.Update(cbcdm);

        ClientScript.RegisterStartupScript(GetType(), "Msg", "alert('修改成功');location.href='" + "NoticeListSet.aspx?action=edit&page="
            + Request["page"].ToString() + "&control=" + Request["control"].ToString() + "&cid=" + Request["cid"].ToString() + "'", true);

    }
}
